package pearls;

import static org.junit.Assert.*;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;

import org.junit.Test;

public class BitmapSortTest {

	@Test
	public final void testSortDistinctIntegers() {
		BitmapSort bs = new BitmapSort();
		
		Random gen = new Random();
		Set<Integer> numbers = new HashSet<Integer>();
		int input[];
		
		for(int N = 10; N <= 10000000; N*=10){
			System.out.print(N + ",");
			
			while(numbers.size() < N){
				numbers.add(gen.nextInt(N*2));
			}
			
			input = new int[N];
			int i = 0;
			for(Integer num : numbers){
				input[i] = num;
				i++;
			}
			
			int temp[] = input;
			long t1 = System.currentTimeMillis();
			Arrays.sort(temp);
			System.out.print((System.currentTimeMillis() - t1) + ",");
			
			t1 = System.currentTimeMillis();
			bs.sortDistinctIntegers(input, 0, N*2);
			System.out.println(System.currentTimeMillis() - t1);
			
			assertArrayEquals(temp, input);
		}
	}

}
